home *** CD-ROM | disk | FTP | other *** search
- /* bt_get.c - get_next, previous entries */
- #include "stdio.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- extern IX_DESC *pci ; /* global variable for current pix */
- RECPOS next_ix() ;
- RECPOS last_ix() ;
-
-
- int get_next(pe,pix) /* get next entry */
- ENTRY *pe ; /* put entry here */
- IX_DESC *pix ; /* points to an index descriptor */
- {
- BLOCK b ;
-
- pci = pix ;
- /* check for dummy entry at end-of-ix */
- copy_current(0,pe) ;
- if( call(pci->pcomp)(pe,& pci->dx.dume) == 0 )
- return( EOIX ) ;
-
- if( next_ix(0,&b) != NULLREC ) /* got next leaf entry ? */
- { copy_current(0,pe) ; /* copy it */
- return( IX_OK) ; /* and return success */
- }
- else return( EOIX ) ;
- }
-
- RECPOS next_ix(l,pb) /* get next entry level */
- int l ; /* level number */
- BLOCK *pb ;
- {
- int off ;
- RECPOS newblk ;
-
- if( l >= pci->dx.nl ) /* above top level ? */
- return( NULLREC ) ; /* yes - failure */
-
- retrieve_block(l,CB(l),pb,CURR) ; /* get current block */
- off = next_entry(pb,CO(l)) ; /* move to next entry in block */
- if( off >= 0 ) /* past end of block */
- CO(l) = off ; /* no - record new position */
- /* yes - move to next index block */
- else
- {
- newblk = next_ix(l+1,pb) ; /* next block on this level */
- if( newblk != NULLREC ) /* check for beginning of index */
- { CB(l) = newblk ; /* make this current block */
- retrieve_block(l,CB(l),pb,CURR) ; /* put in memory */
- CO(l) = 0 ; /* at first entry */
- }
- else return( NULLREC ) ; /* at begin. of index - can't */
- }
- return( ENT_ADR(pb,CO(l))->rptr ) ; /* block no. lower level */
- }
-
-
- int get_previous(pe,pix) /* get previous index entry */
- ENTRY *pe ; /* put the entry here */
- IX_DESC *pix ; /* points to an index descriptor */
- {
- BLOCK b ;
-
- pci = pix ;
- if( last_ix(0,&b) != NULLREC ) /* got next leaf entry ? */
- { copy_current(0,pe) ; /* yes - return it */
- return( IX_OK ) ; /* and success code */
- }
- else return( EOIX ) ; /* no - at BOF. return failure */
- }
-
- RECPOS last_ix(l,pb) /* get previous entry from a level */
- int l ; /* level number */
- BLOCK *pb ; /* space for block */
- {
- int off ;
- RECPOS newblk ;
-
- if( l >= pci->dx.nl )
- return( NULLREC ) ;
-
- retrieve_block(l,CB(l),pb,CURR) ; /* get current block */
- off = prev_entry(pb,CO(l)) ; /* back up one entry */
- if( off >= 0 ) /* past beginning of block */
- CO(l) = off ; /* no - record new offset */
- else
- { newblk = last_ix(l+1,pb); /* yes - get previous block */
- if( newblk != NULLREC ) /* check for begin of index */
- { CB(l) = newblk ; /* make this the current block */
- retrieve_block(l,CB(l),pb,CURR) ; /* put into memory */
- CO(l) = last_entry(pb) ; /* offset = last entry */
- }
- else return( NULLREC ) ; /* at beginning of index - */
- } /* can't back up */
- /* record ptr in curr. entry */
- return( ENT_ADR(pb,CO(l))->rptr ) ;
- }
-
-
- int get_current(pe,pix) /* get current index entry */
- ENTRY *pe ; /* put the entry here */
- IX_DESC *pix ; /* points to an index descriptor */
- {
- pci = pix ;
- copy_current(0,pe) ; /* copy it */
- }
-
-
-